<?php

/**
* AdminGuideListFormModule.class.php
*
* Concrete page module responsable for creating slide show list
*
* @author     Blazej Zieba <b@zieba.info>
* @copyright  2007 konekto.com
* @version    CVS: $Id:$
*/

require_once("framework/PageModule.class.php");
require_once("HTML/QuickForm.php");
require_once("HTML/QuickForm/Renderer/Default.php");


// {{{ SlideShowListModule

class AdminGuideListFormModule extends PageModule 
{
    // {{{ Class operations 

    // {{{ SlideShowListModule
    /**
    * C'tor
    */
    
    function AdminGuideListFormModule()
    {
        trigger_error("ENTER AdminGuideListFormModule::AdminGuideListFormModule()", E_USER_NOTICE);
    }
    // }}}
    // {{{ getContent

    /**
    * Function returns page content
    *
    */

    function getContent()
    {

        trigger_error("ENTER AdminGuideListFormModule::getContent()", E_USER_NOTICE);
        $form = new HTML_QuickForm("GuideListForm", 'post', 'index.php?cmd=AdminGuideList');

        $global = &PEAR::getStaticProperty('CONFIG_INI','GLOBAL');   
        $form->addElement('link',null,_('Lista tras '), $global['service_url'].'index.php?cmd=AdminAddGuide',_('[Dodaj trasę]'));

        $options = &PEAR::getStaticProperty('CONFIG_INI','DSN');    

        $dbh = new PDO($options['dsn_string']);
        $dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
        $sth = $dbh->prepare("SELECT ROWID,name FROM guide WHERE owner = :owner");  
        $sth -> bindParam(':owner',  AuthSingleton::instance()->getUsername() ,PDO::PARAM_STR);    
        $sth -> execute();
        while ( $row = $sth->fetch(PDO::FETCH_ASSOC) )
        {  
            $group = array();
            $group[] =& HTML_QuickForm::createElement('link',null,null, $global['service_url'].'index.php?cmd=AdminShowRoute&id='.$row['rowid'],$row['name'] );
            $group[] =& HTML_QuickForm::createElement('link',null,null, $global['service_url'].'index.php?cmd=AdminRemoveGuide&id='.$row['rowid'],'[Usuń]',array("id" => "AdminRemoveGuide".$row['rowid']));
            $form->addGroup($group, null, null, '&nbsp;');
        }
                 
        $options = &PEAR::getStaticProperty('CONFIG_INI','TEMPLATES');
        $renderer =& new HTML_QuickForm_Renderer_Default($options);
        $renderer -> setFormTemplate(file_get_contents($options["templates_dir"]."form.tpl.xhtml"));
        $renderer -> setElementTemplate(file_get_contents($options["templates_dir"]."formElementStatic.tpl.xhtml"));

        $form->accept($renderer);

        $statusTpl = new HTML_Template_IT($options["templates_dir"]);
        $statusTpl->loadTemplatefile("status.tpl.xhtml",FALSE,FALSE);
        $statusTpl->setVariable("STATUS","Wybierz trasę do edycji");       
 
	    return $statusTpl->get().$renderer->toHtml().$statusTpl->get();
    }
    
    // }}}

    // }}}
}

// }}} 

?>
